package joindemo.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import joindemo.annotation.CheckDeleteMessage;
import joindemo.common.ResponseResult;
import joindemo.service.impl.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/message")
@SaCheckLogin
public class MessageController {


    @Autowired
    private MessageService messageService;

    @CheckDeleteMessage
    @DeleteMapping("/{messageId}")
    public ResponseResult<?> deleteMessage(@PathVariable Long messageId){
        log.info("删除消息接口接收请求，参数：{}",messageId);
        Boolean result=messageService.deleteMessage(messageId);
        if( result){
            log.info("删除消息{}成功",messageId);
            return ResponseResult.success();
        }else{
            log.warn("删除消息业务罗建返回失败");
            return ResponseResult.fail();
        }
    }

    @GetMapping("/count")
    public ResponseResult<?> getUnreadCount(){
        return ResponseResult.success(messageService.getUnreadCount());
    }




}
